# Importing Data
KAZAKISTAN<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Magnesium/Magnesium.xlsx",sheet = "Sheet1", range = "E1:E264")

# Checking the Imported Data
View(KAZAKISTAN)
# Creating Time Series Data
KAZAKISTAN_ts <- ts(KAZAKISTAN, start=c(1998,1), end=c(2018,12), frequency=12)
# Viewing and Checking the Created Time Series Data
KAZAKISTAN_ts
sum(is.na(KAZAKISTAN_ts))
library(forecast)
KAZAKISTAN_ts <- tsclean(KAZAKISTAN_ts)
KAZAKISTAN_ts

# Identification: Plotting the Time Series Data
plot(KAZAKISTAN_ts)

# Estimating the appropriate model
KAZAKISTAN_ts_model <- auto.arima(KAZAKISTAN_ts)
KAZAKISTAN_ts_model

# Forecasting
options(max.print=1000000)
KAZAKISTAN_ts_forecast <- forecast (KAZAKISTAN_ts_model, level=c(95), h=264)
plot(KAZAKISTAN_ts_forecast)
KAZAKISTAN_ts_forecast             

# Exporting
write.table(KAZAKISTAN_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Magnesium/KAZAKISTAN_TSA.csv", sep=",")
